
$(document).ready(function() 
{
	searchParking();
});

//查询车位类型列表
function searchParking()
{
	var parkingNbr = $("#parkingNbr").val();
	var communityName = $("#communityName").val();
	var parkingStatus = $("#parkingStatus").val();
	
	if (parkingStatus == "-1")
	{
		parkingStatus = "";
	}
	
	//alert("parkingNbr-->" + parkingNbr + " communityName-->" + communityName + "parkingStatus-->" + parkingStatus);
	
	$.post("parkingAction!search.action", 
			{inParam : JSON.stringify({"parkingNbr":parkingNbr,"communityName":communityName,"parkingStatus":parkingStatus})}, 
			function(data)
			{
				data = eval("(" + data + ")");
				
				$("#demo").myPagination(
				{
					currPage : data.curPage,
					pageSize : data.pageSize,
					pageCount : data.totalPages,
					
					ajax : 
					{
						on : true, // 开启状态
						url : "parkingAction!search.action",
						dataType : 'json', // 返回类型
						callback : 'callBack',
						param : 
						{
							"on" : true,
							inParam : JSON.stringify({"parkingNbr":parkingNbr,"communityName":communityName,"parkingStatus":parkingStatus})
						},
						ajaxStart : function() {
							return false;
						},
						onClick : function(page) {
							alert(page);
						}
						
			}
		});
	});
}

function callBack(data)
{
	$("#listTable>tbody").children().remove();
	$("#statTable>tbody").children().remove();
	//alert("data-->" + data);
	data = eval("(" + data + ")");
	
	if (data.found != "1")
	{
		alert("未找到相关数据");
	} 
	else 
	{
		var trStr = '';
		
		trStr += '<tr>';
		trStr += '<td>'+data.total+'</td>';
		trStr += '<td>'+data.used+'</td>';
		trStr += '<td>'+data.unused+'</td>';
			
		trStr += '</tr>';
		
		$("#statTable>tbody").append(trStr);
		
		trStr = '';
		
		$(data.data)
		.each(
				function(ix, ite) 
				{	
					trStr += '<tr>';
					
					if (ite.status != "已使用")
					{
						trStr += '<td class="with-checkbox"><input type="checkbox" name="check" value="'+ite.parkingId+'" /></td>';
					}
					else
					{
						trStr += '<td class="with-checkbox"></td>';
					}
					
					trStr += '<td>'+ite.parkingNbr+'</td>';
					trStr += '<td>'+ite.parkingPos+'</td>';
					trStr += '<td>'+ite.communityName+'</td>';
					trStr += '<td>'+ite.parkingType+'</td>';
					trStr += '<td>'+ite.plateNbr+'</td>';					
					trStr += '<td>'+ite.room+'</td>';
					trStr += '<td>'+ite.status+'</td>';
					
					trStr += '<td>';
					trStr += '<a href="updateParking.jsp?parkingId='+ite.parkingId+'" class="btn">修改</a>';
					
					if (ite.status != "已使用")
					{
						trStr += '<a href="javascript:removeParking('+ite.parkingId+');" class="btn">删除</a>';
					}
					
					trStr += '</td>';
					
					trStr += '</tr>';					
					
				});
//		alert("trStr-->" + trStr);
		$("#listTable>tbody").append(trStr);
	}
	
}

//删除车位类型
function removeParking(pId) 
{
	var chk_value =[];
	chk_value.push(pId);
	
	$.altmodal("删除", "您确定要删除车位信息吗?",1000,function(){		
		$.post("parkingAction!removeParking.action",{inParam:JSON.stringify(chk_value)},function(data) {
			
			data = eval("("+data+")");
			
			if (data.ok == "1")
			{
				alert("删除成功");
				
				searchParking();
			} 
			else
			{
				alert("删除失败");
			} 
		});
	});
}



function removeAllParking() 
{
	var chk_value =[]; 
	$('input[name="check"]:checked').each(function(){ 
		chk_value.push($(this).val()); 
	}); 
	
	if (chk_value.length == 0) 
	{
		$.sucmodal("提示", "请勾选要删除的车位信息",2000);
		return;
	}
	
	$.altmodal("删除", "您确定要删除所选的车位信息吗?",1000,function(){
		$.post(
			"parkingAction!removeParking.action",
			{"inParam":JSON.stringify(chk_value)},
			function(data)
			{
				data = eval("("+data+")");
				
				if(data.ok == "1")
				{
					$.sucmodal("提交成功", "车位删除成功。",2000,function(){
						searchParking();
	            	});
				}
				else
				{
					$.sucmodal("提交失败", "请于管理员联系",2000);
				}
			}
		);
	});
}